<?php
/* 
 * 项目处理
 * 分析项目是否已经到期，到期的项目强制将项目和问卷设为完成状态
 * 完成状态的问卷不能再对标和修改
 */
class ProjectCommand extends  CConsoleCommand{
    public function run($args){
        $project = new Project();
        //到日期未启动的项目设为启动
        $criteria = new CDbCriteria();
        $criteria->addCondition('start_time<="'.date('Y-m-d').'"');
        $criteria->addColumnCondition(array('status' => -1));
        $list = $project->findAll($criteria);
        if ($list) {
            echo "今日启动项目\r\n";
            foreach ($list as $key => $val) {
                echo $val['project_id']."\r\n";
                Project::model()->updateByPk($val['project_id'], array('status' => 1));
            }
        }
        
        
        //结束的项目到日期设为完结,网点问卷也设为完结
        $criteria = new CDbCriteria();
        $criteria->addCondition('end_time<="'.date('Y-m-d').'"');
        $list = $project->findAll($criteria);
        if ($list) {
            echo "已结束项目";
            foreach ($list as $key => $val) {
                echo $val['project_id']."\r\n";
                Project::model()->updateByPk($val['project_id'], array('status' => 2));
                NetworkQuestion::model()->updateAll(array('status' => 2),'project_id=:project_id',array(':project_id' => $val['project_id']));
                QuestionBase::model()->updateAll(array('status' => QuestionBase::QUESTION_COMPLETE),'project_id=:project_id',array(':project_id' => $val['project_id']));
            }
        }
    }
}
